package common

import (
	"strconv"
	"strings"
)

//比较合约版本号，ver < otherVer ? false:true
func ContractVersionCompare(ver string, otherVer string) bool {
	newVers := strings.Split(ver, ".")
	oldVers := strings.Split(otherVer, ".")
	var newVersionNumber uint32
	var oldVersionNumber uint32
	for i := 0; i < 3; i++ {
		nn, _ := strconv.ParseFloat(newVers[i], 16)
		no, _ := strconv.ParseFloat(oldVers[i], 16)
		if i == 0 {
			newVersionNumber = uint32(nn)
			oldVersionNumber = uint32(no)
		} else {
			newVersionNumber = newVersionNumber*1000 + uint32(nn)
			oldVersionNumber = oldVersionNumber*1000 + uint32(no)
		}
	}
	if newVersionNumber < oldVersionNumber {
		return false
	}
	return true
}